package group.program.Controller;

import group.program.Service.*;
import group.program.utils.OSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Slf4j
@RestController
@RequestMapping("File")
public class FileInformationExtractionController {
    @Autowired
    private OSSUtils ossUtils;
    @Autowired
    private TxtService txtService;
    @Autowired
    private NlpService nlpService;
    @Autowired
    private DocService docService;
    @Autowired
    private DocxService docxService;
    @Autowired
    private PdfService pdfService;
    @PostMapping("/InformationExtraction")
    public void InformationExtraction(HttpServletResponse response,@RequestParam("file") MultipartFile file) {
        String contentType = file.getContentType();
        String information="";
        if("text/plain".equals(contentType)){
            information=txtService.extractInformation(file);
        }else if ("application/msword".equals(contentType)) {
            information=docService.extractInformation(file);
        }else if ("application/vnd.openxmlformats-officedocument.wordprocessingml.document".equals(contentType)) {
            information=docxService.extractInformation(file);
        } else if ("application/pdf".equals(contentType)) {
            information=pdfService.extractInformation(file);
        }
        //文件信息传给大模型
        nlpService.getNlpApi(response,information);
    }
}
